﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CIRDiagnoseDevice.DBManage;

namespace CIRDiagnoseDevice
{
    public partial class DeviceInfoFrm : Form
    {
        private DbManage dbManage = new DbManage();
        public event ButtonClickNotice OnButtonClick;
        public DeviceInfoFrm()
        {
            InitializeComponent();
            this.OnButtonClick += new ButtonClickNotice(MainFrm.MotherFrm.MainFrm_OnButtonClick);
        }


        private void simpleButton1_Click_1(object sender, EventArgs e)
        {
            if (textBox14.Text != "")
            {
                try
                {
                    dbManage.InsertData(MainFrm.device.Cab_bur, MainFrm.device.Cab_seg, MainFrm.device.Cab_pl, MainFrm.device.Cab_num, MainFrm.device.Cab_db, MainFrm.device.Cab_xc,
                                                         MainFrm.device.Dev_bur, MainFrm.device.Dev_seg, MainFrm.device.Dev_ws, MainFrm.device.Dev_wa, MainFrm.device.Dev_man,
                                                         MainFrm.device.Dev_mod, MainFrm.device.Dev_num, MainFrm.device.Dev_xc);
                    OnButtonClick(this);
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("请填写完整设备信息！");
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            if (sender is TextBox)
            {
                TextBox tBox = (TextBox)sender;
               if (tBox.Name == "textBox3")
                {
                    MainFrm.device.Cab_seg = textBox3.Text;
                    
                }
                else if (tBox.Name == "textBox4")
                {
                    MainFrm.device.Cab_pl = textBox4.Text;
                }
                else if (tBox.Name == "textBox5")
                {
                    MainFrm.device.Cab_num = textBox5.Text;
                }
                else if (tBox.Name == "textBox9")
                {
                    MainFrm.device.Dev_seg = textBox9.Text;
                }
                else if (tBox.Name == "textBox10")
                {
                    MainFrm.device.Dev_ws = textBox10.Text;
                }
                else if (tBox.Name == "textBox11")
                {
                    MainFrm.device.Dev_wa = textBox11.Text;
                }
                else if (tBox.Name == "textBox12")
                {
                    MainFrm.device.Dev_man = textBox12.Text;
                }
                else if (tBox.Name == "textBox13")
                {
                    MainFrm.device.Dev_mod = textBox13.Text;
                }
                else if (tBox.Name == "textBox14")
                {
                    MainFrm.device.Dev_num = textBox14.Text;
                }
            }
            else if (sender is ComboBox)
            {
                ComboBox comBox = (ComboBox)sender;
                if (comBox.Name == "textBox2")
                {
                    MainFrm.device.Cab_bur = textBox2.Text;
                }
                else if (comBox.Name == "textBox6")
                {
                    MainFrm.device.Cab_db = int.Parse(textBox6.Text);
                }
                else if (comBox.Name == "textBox7")
                {
                    MainFrm.device.Cab_xc = textBox7.Text;
                }
                else if (comBox.Name == "textBox8")
                {
                    MainFrm.device.Dev_bur = textBox8.Text;
                }
                else if (comBox.Name == "textBox15")
                {
                    MainFrm.device.Dev_xc = textBox15.Text;
                }
            }
        }

        private void DeviceInfoFrm_Load(object sender, EventArgs e)
        {
            textBox2.Text = MainFrm.device.Cab_bur;
            textBox3.Text = MainFrm.device.Cab_seg;
            textBox4.Text = MainFrm.device.Cab_pl;
            textBox5.Text = MainFrm.device.Cab_num;
            textBox6.Text = MainFrm.device.Cab_db.ToString();
            textBox7.Text = MainFrm.device.Cab_xc;
            textBox8.Text = MainFrm.device.Dev_bur;
            textBox9.Text = MainFrm.device.Dev_seg;
            textBox10.Text = MainFrm.device.Dev_ws;
            textBox11.Text = MainFrm.device.Dev_wa;
            textBox12.Text = MainFrm.device.Dev_man;
            textBox13.Text = MainFrm.device.Dev_mod;
            textBox14.Text = MainFrm.device.Dev_num;
            textBox15.Text = MainFrm.device.Dev_xc;
        }
    }
}
